import java.util.Arrays;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/23
 * \* Time: 11:25
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 准时到达的列车最小时速 {
    public int minSpeedOnTime(int[] dist, double hour) {
        if(dist.length>=hour+1){
            return -1;
        }
        if(dist.length-1==(int)hour){
            hour=hour-(double) (dist.length-1);
            return (int) (dist[dist.length-1]/hour);
        }

        int []dist1 =new int[dist.length];
        for(int i=0;i<dist.length;i++){
            dist1[i]=dist[i];
        }
        Arrays.sort(dist1);
        double h=hour;
        double time=0;
        int time1=0;
        //最大速度
        int tmp=dist1[dist1.length-1];
        int tmp1=0;
        for(int i=tmp;i>=1;i--){
            h=hour;
            for(int j=0;j<dist.length;j++){
                if((double)dist[j]%(double)i==0){
                    h=h-dist[j]/i;
                }else if((double)dist[j]%(double)i!=0){
                    time=(double)dist[j]/(double)i;
                    time1=(int)time+1;
                    if(j!=dist.length-1){
                        h-=time1;
                    }else if(j==dist.length-1){
                        h-=time;
                    }

                    if(h<0) {
                        tmp = i + 1;
                        break;
                    }
                }
            }
            if(h<0){
                tmp=i+1;
                break;
            }else{
                tmp=i;
            }
        }
        return tmp;
    }
}